package userTests;

import org.testng.annotations.Test;
import org.openqa.selenium.*;

public class CreateBillTests extends TestBaseUser {

	@Test
	public void testCreateBill() {
		openMainPageUser();
		gotoSignInUser();
		LoginLogoutDataUser login = new LoginLogoutDataUser();
		login.phoneNumber = "955413233";
		login.password = "!23Qwe";
		fillSignInUser(login);
		submitSignInUser();
		
		isAntiFishingImgPresent();
		pointCurrency();
		gotoCreateBillForm();
		fillBillForm();
		submitNext();
		gotoEditBillForm();
		editBillForm();
		submitNext();
		submitBillCreation();

		isAlertSuccessBlockPresent();
		logout();
		confirmMainPageUser();
	}


	private void submitBillCreation() {
		wd.findElement(By.name("confirm")).click();
	}

	private void editBillForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("20");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380997047402");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("auto2");
	}

	private void gotoEditBillForm() {
		wd.findElement(By.name("edit")).click();
	}

	private void submitNext() {
		wd.findElement(By.name("preview")).click();
	}

	private void fillBillForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("10");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380999999998");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("auto");
	}

	private void gotoCreateBillForm() {
		wd.findElement(By.id("btnBill")).click();
	}

}
